# -*- coding: utf-8 -*-

# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://doc.scrapy.org/en/latest/topics/item-pipeline.html
from selenium import webdriver
from pymongo import MongoClient

conn = MongoClient()
co = conn['XC']['airport']


class XtPipeline(object):
    # 打开爬虫的时候开启selenium
    def open_spider(self, spider):
        spider.driver = webdriver.Chrome()
        spider.driver.maximize_window()

    def process_item(self, item, spider):
        print(item)
        co.insert_one(item)
        return item

    # 关闭爬虫的时候关闭selenium
    def close_spider(self, spider):
        spider.driver.quit()
